package com.heima.wemedia.service.impl;

import com.heima.common.contatns.ScheduleConstants;
import com.heima.model.schedule.dtos.Task;
import com.heima.model.wemeida.pojos.WmNews;
import com.heima.task.feign.TaskFeign;
import com.heima.utils.common.JsonUtils;
import com.heima.wemedia.service.WmNewsTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class WmNewsTaskServiceImpl implements WmNewsTaskService {
    @Autowired
    private TaskFeign taskFeign;
    @Override
    public void addTaskToList(WmNews wmNews) {
        //创建Task对象
        Task task = new Task();
        task.setExecuteTime(wmNews.getPublishTime().getTime());
        task.setTaskTopic(ScheduleConstants.TASK_TOPIC_NEWS_PUBLISH);

        WmNews taskWmNews = new WmNews();
        taskWmNews.setId(wmNews.getId());
        task.setParameters(JsonUtils.toString(taskWmNews));

        //把Task对象通过Feign接口存入延迟任务队列中
        taskFeign.addTask(task);

        log.info("该文章已加入文章发布队列中 {} id:"+wmNews.getId());
    }
}
